package org.dxy.infrastructure.persistent.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import lombok.extern.slf4j.Slf4j;
import org.dxy.infrastructure.entity.query.WorkstationBasicViewEntity;
import org.dxy.infrastructure.persistent.mapper.WorkstationBasicViewMapper;
import org.dxy.infrastructure.persistent.service.WorkstationBasicViewService;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * 工位基础视图服务实现类
 * @author dxy
 * @createTime 2025/9/4
 */
@Slf4j
@Service
public class WorkstationBasicViewServiceImpl extends ServiceImpl<WorkstationBasicViewMapper, WorkstationBasicViewEntity> 
        implements WorkstationBasicViewService {

    @Override
    public boolean existsByWorkstationCode(String workstationCode) {
        LambdaQueryWrapper<WorkstationBasicViewEntity> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.eq(WorkstationBasicViewEntity::getWorkstationCode, workstationCode);
        return this.count(queryWrapper) > 0;
    }

    @Override
    public List<WorkstationBasicViewEntity> getByProductionLineId(Long productionLineId) {
        LambdaQueryWrapper<WorkstationBasicViewEntity> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.eq(WorkstationBasicViewEntity::getProductionLineId, productionLineId);
        queryWrapper.orderByAsc(WorkstationBasicViewEntity::getPosition);
        return this.list(queryWrapper);
    }

    @Override
    public List<WorkstationBasicViewEntity> getEnabledByProductionLineId(Long productionLineId) {
        LambdaQueryWrapper<WorkstationBasicViewEntity> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.eq(WorkstationBasicViewEntity::getProductionLineId, productionLineId);
        queryWrapper.in(WorkstationBasicViewEntity::getStatus, "IDLE", "RUNNING");
        queryWrapper.orderByAsc(WorkstationBasicViewEntity::getPosition);
        return this.list(queryWrapper);
    }
}